package cn.intotw.rdcj.task.spiders.util;

import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.cookie.ClientCookieEncoder;
import io.netty.handler.codec.http.cookie.DefaultCookie;

/**
 * Created by Chenxiang
 *
 * @generator: IntelliJ IDEA
 * @description: Http请求头工厂类
 * @project: rdcj
 * @package: cn.intotw.rdcj.task.spiders.util
 * @date: 2020年07月24日 14时47分
 */
public final class HttpHeaderFactory {
    public static HttpHeaders getBiqugeHeaders(int contentLength){
        HttpHeaders httpHeaders=new DefaultHttpHeaders();
        httpHeaders.set(HttpHeaderNames.ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        httpHeaders.set(HttpHeaderNames.ACCEPT_ENCODING, "gzip, deflate");
        httpHeaders.set(HttpHeaderNames.ACCEPT_LANGUAGE, "zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7");
        httpHeaders.set(HttpHeaderNames.CACHE_CONTROL, "max-age=0");

        httpHeaders.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED);
        if(contentLength!=0){
            httpHeaders.set(HttpHeaderNames.CONTENT_LENGTH, contentLength);
        }
        httpHeaders.set(HttpHeaderNames.HOST, "www.xbiquge.la");
        httpHeaders.set(HttpHeaderNames.ORIGIN, "http://www.xbiquge.la");
        httpHeaders.set(HttpHeaderNames.PROXY_CONNECTION, HttpHeaderValues.KEEP_ALIVE);
        httpHeaders.set(HttpHeaderNames.REFERER, "http://www.xbiquge.la/modules/article/waps.php");
        httpHeaders.set("Upgrade-Insecure-Requests", "1");
        httpHeaders.set(HttpHeaderNames.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36");


        // Set some example cookies.
        httpHeaders.set(
                HttpHeaderNames.COOKIE,
                ClientCookieEncoder.STRICT.encode(
                        new DefaultCookie("_abcde_qweasd", "0"),
                        new DefaultCookie("_abcde_qweasd", "0")));
        return httpHeaders;
    }
}
